import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt

def auto_text(rects): #绘线
    for rect in rects:
        plt.text(rect.get_x(), rect.get_height(), '{:.2f}'.format(rect.get_height()), ha='left', va='bottom')

datafile = './文本/客运量_1-1.csv' #第一行为属性标签
tempfile = './文本/1_4_temp.xlsx' #临时文件
data = pd.DataFrame(pd.read_csv(datafile))

DataFrame(data.groupby(data['Year'].apply(lambda x:x)).sum().drop(['Year'],axis=1)).to_excel(tempfile,sheet_name = 'sheet1',header=True) #求和
data2 = pd.read_excel(tempfile)

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.xlabel('年份')
plt.ylabel('人数')
fig = plt.figure()
plt.title('各年份客运量分布情况')
rect = plt.bar(data2['Year'],data2['Whole year'],color = 'blue') #绘制直方图，设定颜色为蓝色
plt.plot(data2['Year'],data2['Whole year'],'ko-') #绘制折线图
auto_text(rect)
plt.show()